package main;

import java.awt.Graphics;
import java.awt.Graphics2D;

import com.sun.corba.se.impl.copyobject.FallbackObjectCopierImpl;


public class ShipEntity extends Entity {
	
	private double angle;
	
	private double angleOfThrust;
	
	private int thrust;
	
	private double vx;
	
	private double grav;
	
	public ShipEntity( MainGame game, String ref, long x, long y ) {
		super( ref, x, y );
	}
	
	@Override
	public void move( long delta ) {
		
		this.dx =  Math.cos( Math.toRadians(angleOfThrust) ) * vx;
		
		if ( vx > 0 ) {
			this.dy =  Math.sin( Math.toRadians(angleOfThrust) ) * vx;
		}
				
//		System.out.println("A = " + angle + ", Th = " + vx);
		
		if (( dx < 0 ) && ( x < 10 )) {
			return;		
		}
		
		if (( dx > 0 ) && ( x > 750 )) {
			return;
		}
		
		if (( dy > 0) && ( y > 550 )) {
			return;
		}
		
		if ( (dy != 0 ) && ( y < 5 ) ) {
			y += 2;
			return;
		}
				
		super.move(delta);
	}
	
	//Rotate the ship - 0 = left, 1 = right
	public void rotate( int direction ) {
		if ( direction == 1 ) {
			angle += 5;
		} else {
			angle -= 5;
		}
	}
	
	@Override
	public void draw( Graphics g ) {
		int h = getSprite().getHeight();
		int w = getSprite().getWidth();
		( (Graphics2D) g).rotate( Math.toRadians( angle ), getX()+ ( w / 2 ), getY() + ( h / 2 ) );
		getSprite().draw( g, (int)x, (int)y);
	}

	public void setThrust(int i) {
		if ( thrust <= 20 && thrust >= 0) {
			thrust = i;
		}
	}
	
	public int getThrust() {
		return thrust;
	}

	public void setVx(double i) {
		vx = i;		
	}
	
	public double getVx() {
		return vx;
	}
	
	public void setGrav( double g ) {
		grav = g;
	}
	
	public void setAngle( double a ) {
		angle = a;
	}
	
	public double getAngle() {
		return angle;
	}
	
	public void setAngleOfThrust() {
		angleOfThrust = angle;
	}
	
	public double getAngleOfThrust() {
		return angleOfThrust;
	}
	
	

}


























